#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
tuple<int, int, int> tu[N];

void solve()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        tu[i] = {l, r, i};
    }
    sort(tu, tu + n);
    set<int> se;
    vector<int> ans(n);
    map<int, priority_queue<int>> mp;
    for(int i = 0; i < n; i++) {
        int l = get<0>(tu[i]), r = get<1>(tu[i]), idx = get<2>(tu[i]);
        if(se.empty()){
            ans[idx] = 0;
        }
        auto p = lower_bound(se.begin(), se.end(), r);
        if(p == se.end()){
            ans[idx] = 0;
        }else{
            // cout << *p << endl;
            ans[idx] = *p - r + l - mp[*p].top();
        }
        mp[r].push(l);
        se.insert(r);
    }
    for(auto x : ans){
        cout << x << endl;
    }
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}